﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Estimate.Common.DBFieldTypes;
using Estimate.Common.Estimate;

namespace EstimateService
{
    public partial class ZytHandinReportHandler : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string year = Request.QueryString["year"] != null ? Request.QueryString["year"].ToString() : "";
            string month = Request.QueryString["month"] != null ? Request.QueryString["month"].ToString() : "";
            string semitype = Request.QueryString["semitype"] != null ? Request.QueryString["semitype"].ToString() : "";
            string type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : "";
            string tid = Request.QueryString["tid"] != null ? Request.QueryString["tid"].ToString() : "";

            if (year != "" && month != "" && semitype != "" && type != "" && tid != "")
                Response.Write(ZytHandinReport(year, month, semitype, type, tid));
        }

        /// <summary>
        /// 考核报表
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="semitype"></param>
        /// <param name="type">报表类型</param>
        /// <param name="tid"></param>
        /// <returns></returns>
        private string ZytHandinReport(string year, string month, string semitype, string type, string tid)
        {
            string connectionString = ConfigurationManager.AppSettings["ConnectionString"];
            ForeSemiType semiType = (ForeSemiType)Enum.Parse(typeof(ForeSemiType), semitype);
            ZytHandinReportType reportType = (ZytHandinReportType)Enum.Parse(typeof(ZytHandinReportType), type);
            DateTime beginDate = new DateTime(int.Parse(year), int.Parse(month), 1);
            DateTime endDate = beginDate.AddMonths(1).AddDays(-1);

            Estimate.Reports.ZytHandinReport zytHandinReport = new Estimate.Reports.ZytHandinReport(connectionString, reportType, tid);
            zytHandinReport.PrepareData(beginDate, endDate, semiType);
            return zytHandinReport.GetReportDataString();
        }
    }
}